'''
读取通讯录.txt文件,并将文件中的内容转成列表.

文件内容样式:
张三 13012345678 4
李四 13012345679 4
王五 13054636925 15
赵六 13054636926 15

转换后返回的列表:
['张三', '13012345678', '4', '李四', '13012345679', '4', '王五', '13054636925', '15', '赵六', '13054636926', '15']
'''
def read_txl():
    txls=[]
    with open('通讯录.txt','r',encoding='utf-8') as f:
        for line in f:
            line=line.rstrip("\n").split(" ")
            txls.append(line)
    txls = [item for row in txls for item in row]
    return txls


'''
将列表内容存入文件.

传入的列表:
['张三', '13012345678', '4', '李四', '13012345679', '4', '王五', '13054636925', '15', '赵六', '13054636926', '15']

写入后的文件内容:
张三 13012345678 4
李四 13012345679 4
王五 13054636925 15
赵六 13054636926 15
'''
def write_txl(txl):
    with open('通讯录.txt','w',encoding='utf-8') as f:
        for i in range(0, len(txl), 3):
                line = ' '.join(txl[i:i+3])
                f.write(line + '\n')